package com.sps.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sps.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sps.common.annotation.Log;
import com.sps.common.core.controller.BaseController;
import com.sps.common.core.domain.AjaxResult;
import com.sps.common.enums.BusinessType;
import com.sps.business.domain.JcItemInfo;
import com.sps.business.service.IJcItemInfoService;
import com.sps.common.utils.poi.ExcelUtil;
import com.sps.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 物料信息Controller
 * 
 * @author 王超
 * @date 2024-12-10
 */
@RestController
@RequestMapping("/business/jciteminfo")
public class JcItemInfoController extends BaseController
{
    @Autowired
    private IJcItemInfoService jcItemInfoService;

    /**
     * 查询物料信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:jciteminfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcItemInfo jcItemInfo)
    {
        startPage();
        List<JcItemInfo> list = jcItemInfoService.selectJcItemInfoList(jcItemInfo);
        return getDataTable(list);
    }

    /**
     * 导出物料信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:jciteminfo:export')")
    @Log(title = "物料信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcItemInfo jcItemInfo)
    {
        List<JcItemInfo> list = jcItemInfoService.selectJcItemInfoList(jcItemInfo);
        ExcelUtil<JcItemInfo> util = new ExcelUtil<JcItemInfo>(JcItemInfo.class);
        util.exportExcel(response, list, "物料信息数据");
    }

    /**
     * 获取物料信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:jciteminfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcItemInfoService.selectJcItemInfoById(id));
    }

    /**
     * 新增物料信息
     */
    @PreAuthorize("@ss.hasPermi('business:jciteminfo:add')")
    @Log(title = "新增物料信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcItemInfo jcItemInfo)
    {
        return toAjax(jcItemInfoService.insertJcItemInfo(jcItemInfo));
    }

    /**
     * 修改物料信息
     */
    @PreAuthorize("@ss.hasPermi('business:jciteminfo:edit')")
    @Log(title = "物料信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcItemInfo jcItemInfo)
    {
        return toAjax(jcItemInfoService.updateJcItemInfo(jcItemInfo));
    }

    /**
     * 删除物料信息
     */
    @PreAuthorize("@ss.hasPermi('business:jciteminfo:remove')")
    @Log(title = "删除物料信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcItemInfoService.deleteJcItemInfoByIds(ids));
    }


    /**
     * 物料导入模板
     */
    @PostMapping("/importTemplate")
    @Log(title = "导入物料信息", businessType = BusinessType.IMPORT)
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<JcItemInfo> util = new ExcelUtil<JcItemInfo>(JcItemInfo.class);
        util.importTemplateExcel(response, "物料数据");
    }


    @Log(title = "物料导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<JcItemInfo> util = new ExcelUtil<JcItemInfo>(JcItemInfo.class);
        List<JcItemInfo> itemList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = jcItemInfoService.importItem(itemList, updateSupport, operName);
        return success(message);
    }

    /**
     * 获取物料信息详细信息
     */
    @GetMapping(value = "/getJciteminfoByCode/{itemCode}")
    public AjaxResult getJciteminfoByCode(@PathVariable("itemCode") String itemCode)
    {
        return success(jcItemInfoService.selectJcItemInfoByItemCode(itemCode));
    }

    /**
     * 获取物料信息详细信息,根据货位号（标签）
     */
    @GetMapping(value = "/getJciteminfoByLable/{lableCode}")
    public AjaxResult getJciteminfoByLable(@PathVariable("lableCode") String lableCode)
    {
        return success(jcItemInfoService.selectJcItemInfoByLableCode(lableCode));
    }


}
